<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>

<%@page import="java.sql.Connection"%>

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
    <%
    
    String location = request.getParameter("location");
    System.out.println("location="+location);
    
    
    if(location != ""){
    
    
	Class.forName("oracle.jdbc.driver.OracleDriver"); 
	String url = "jdbc:oracle:thin:@127.0.0.1:1521:XE"; 
	String user = "student";			
	String password = "1234";	
	Connection conn = null;
	Statement stmt= null;
	Statement stmt1= null;
	Statement stmt2= null;
	ResultSet rs = null;
	ResultSet rs1 = null;
	ResultSet rs2 = null;
	conn = DriverManager.getConnection(url,user,password);
	
	String sql= "select zipcode,sido,gugun,dong,BUNJI from ziptbl where dong like '%"+location+"%' ";
	String sql1="select zipcode,sido,gugun,dong,BUNJI from ziptbl where sido like '%"+location+"%' ";
	String sql2="select zipcode,sido,gugun,dong,BUNJI from ziptbl where gugun like '%"+location+"%' ";
	
	stmt = conn.createStatement();
	stmt1 = conn.createStatement();
	stmt2 = conn.createStatement();
	
	rs = stmt.executeQuery(sql);
	rs1 = stmt1.executeQuery(sql1);
	rs2 = stmt2.executeQuery(sql2);
	
	out.println("<rs>");

	while(rs.next()){
		String zipcode = rs.getString(1);
		String sido = rs.getString(2);
		String gugun = rs.getString(3);
		String dong = rs.getString(4);
		String bunji = rs.getString(5);
		
		out.println("<result>");
		out.println( "<zipcode>"+zipcode+"</zipcode>"   );
		out.println( "<sido>"+sido+"</sido>"  );
		out.println( "<gugun>"+gugun+"</gugun>" );
		out.println( "<dong>"+dong+"</dong>" );
		out.println( "<bunji>"+bunji+"</bunji>" );
		out.println("</result>");
		
		//System.out.println(zipcode+sido+gugun+dong+bunji);
		
	}
	
	 while(rs1.next()){
		String zipcode = rs1.getString(1);
		String sido = rs1.getString(2);
		String gugun = rs1.getString(3);
		String dong = rs1.getString(4);
		String bunji = rs1.getString(5);
		
		out.println("<result>");
		out.println( "<zipcode>"+zipcode+"</zipcode>"   );
		out.println( "<sido>"+sido+"</sido>"  );
		out.println( "<gugun>"+gugun+"</gugun>" );
		out.println( "<dong>"+dong+"</dong>" );
		out.println( "<bunji>"+bunji+"</bunji>" );
		out.println("</result>");
		
		//System.out.println(zipcode+sido+gugun+dong+bunji);
		
	}
	 
	while(rs2.next()){
		String zipcode = rs2.getString(1);
		String sido = rs2.getString(2);
		String gugun = rs2.getString(3);
		String dong = rs2.getString(4);
		String bunji = rs2.getString(5);
		
		out.println("<result>");
		out.println( "<zipcode>"+zipcode+"</zipcode>"   );
		out.println( "<sido>"+sido+"</sido>"  );
		out.println( "<gugun>"+gugun+"</gugun>" );
		out.println( "<dong>"+dong+"</dong>" );
		out.println( "<bunji>"+bunji+"</bunji>" );
		out.println("</result>");
		
		//System.out.println(zipcode+sido+gugun+dong+bunji);
	} 
    
	out.println("</rs>");
	
    }else {
    	out.println("<rs>");
    	
    	out.println("</rs>");
    }
	
	
	%>